{

    //ES5 ES3默认参数的写法
    function f(x,y,z){
        if(y === undefined){
            y=7;
        }
        if(z === undefined){
            z=42;
        }
        return x+y+z;
    }
    console.log(f(1,3));

}


{

    //ES6默认参数
    function f(x,y=7,z=42){
        return x+y+z;
    }
    console.log(f(1,undefined,3));

}

{
    //必填参数
    function checkParam(){
        throw new Error('parameter can\'t be empty!')
    }

    function f(x = checkParam(), y = 7, z = 42){
        return x + y + z;
    }
    console.log(f(1))

    try {
        f();
    } catch (e) {
        console.error(e)
    }finally{

    }
        
}


{

    //ES3 ES5可变参数
    function f(){
        var a = Array.prototype.slice.call(arguments);
        var sum = 0;
        a.forEach(function(item){
            sum+=item*1;
        });
        return sum;
    }
    console.log(f(1,2,3))
}

{
    //ES6可变参数
    function f(...a){
        var sum = 0
        a.forEach(function(item){
            sum+=item;
        })
        return sum;
    }
    console.log(f(1,2,3,6))

}

{
    //ES5合并数组
    var params = ['hello', true, 7];
    var other = [1,2].concat(params);
    console.log(other);
}

{
    //ES6 利用扩展运算符合并数组
    var params = ['hello', true, 7];
    var other = [
        1, 2, ...params
    ];
    console.log(other)
}